package com.practice.book.model;

import lombok.Data;

import static com.practice.book.constant.Constants.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-22
 * Time: 20:30
 */
@Data
public class Result<T> {
    private int code;//200 代表成功   -1代表登入失败   -2代表程序登入成功，但是程序出错
    private String errMes;
    private T data;

    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        result.setErrMes("");
        return result;
    }

    public static <T> Result unLogin() {
        Result result = new Result();
        result.setCode(UNLOGIN_CODE);
        result.setErrMes("登入失败!");
        return result;
    }


    public static <T> Result loginButFail(T data) {
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setData(data);
        result.setErrMes("登入成功，程序有误!");
        return result;
    }

    public static <T> Result loginButFail() {
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setErrMes("登入成功，程序有误!");
        return result;
    }
}
